package com.iss.apartmentmanage.controller.check;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iss.apartmentmanage.entity.Reserve;
import com.iss.apartmentmanage.model.MyResponseData;
import com.iss.apartmentmanage.service.impl.ReserveServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reserve")
@Api(description = "预定信息模块接口",value = "ReserveController")
public class ReserveController {
    @Autowired
    ReserveServiceImpl reserveService;

    /**
     * 预订信息全部查询和条件查询
     */
    @PostMapping("/selectAllReserveMessage")
    @ResponseBody
    public MyResponseData selectAllReserveMessage(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody  Reserve reserve) {
        MyResponseData myResponseData = new MyResponseData();
        IPage<Reserve> iPage = reserveService.selectAllReserveMessage(pageNum, pageSize, reserve);
        if (iPage != null) {
            myResponseData.setErrorCode(1);
            myResponseData.setObject(iPage);
            myResponseData.setMsg("查询成功");
        } else {
            myResponseData.setErrorCode(-1);
            myResponseData.setMsg("查询失败");
        }
        return myResponseData;
    }

    /**
     * 预订信息的插入
     */
    @RequestMapping(value = "/insertReserveMessage", method = RequestMethod.POST)
    public MyResponseData insertReserveMessage(@RequestBody Reserve reserve) {
        MyResponseData myResponseData = new MyResponseData();
        int count = reserveService.insertReserve(reserve);
        if (count != 0) {
            myResponseData.setMsg("添加成功");
            myResponseData.setErrorCode(1);
        } else {
            myResponseData.setErrorCode(-1);
        }
        return myResponseData;
    }

    /**
     * 预订信息的更新
     */
    @RequestMapping(value = "/updateReserveMessage", method = RequestMethod.POST)
    public MyResponseData updateReserveMessage(@RequestBody Reserve reserve) {
        MyResponseData myResponseData = new MyResponseData();
        int count = reserveService.updateReserve(reserve);
        if (count != 0) {
            myResponseData.setMsg("更新成功");
            myResponseData.setErrorCode(1);
        } else {
            myResponseData.setErrorCode(-1);
        }
        return myResponseData;
    }
    /**
     * 预订信息的删除
     */
    @RequestMapping(value = "/deleteReserveMessage", method = RequestMethod.POST)
    public MyResponseData deleteReserveMessage(@RequestBody Reserve reserve) {
        MyResponseData myResponseData = new MyResponseData();
        int count = reserveService.deleteReserve(reserve.getId());
        if (count != 0) {
            myResponseData.setMsg("删除成功");
            myResponseData.setErrorCode(1);
        } else {
            myResponseData.setErrorCode(-1);
        }
        return myResponseData;
    }























}
